//- Copyright (C) 2018-2022 Chatopera Inc, <https://www.chatopera.com>
//- 
//- Licensed under the Apache License, Version 2.0 (the "License");
//- you may not use this file except in compliance with the License.
//- You may obtain a copy of the License at
//- 
//-  http://www.apache.org/licenses/LICENSE-2.0
//- 
//-  Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
extends /admin/include/layout.pug

block content
    .row(style='height:100%;')
        .col-lg-3(style='border-right:1px solid #e6e6e6;padding-right:0px;')
            h1.site-h1(style='background-color:#FFFFFF;')
                | 角色列表
                if user.superadmin
                    span(style='float:right;')
                        button.layui-btn.layui-btn-small.green(href='/admin/role/add.html', data-toggle='ajax', data-height='200', data-width='550', data-title='新建角色')
                            | 新建角色
            .row(style='padding:5px;')
                .col-lg-12
                    ul
                        if size(roleList) > 0
                            for role in roleList
                                li.uk_role(class={'this': roleData.id == role.id})
                                    a(href="/admin/role/index.html?role=" + role.id, style="word-wrap: break-word;word-break: break-all;")
                                        i.kfont(style="margin-top: 3px;float: left") &#xe7d0;
                                        | #{role.name}
                        else
                            .ukefu-empty(style="background: none;")
                                i.layui-icon 
                                div(style="") 还没有角色
        .col-lg-9
            h1.site-h1(style='background-color:#FFFFFF;')
                span(style='width:200px;display:inline-block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;word-wrap: break-word;word-break: break-all;')
                    if roleData
                        | #{roleData.name}
                    else
                        | 角色用户
                    if userList
                        | （#{userList.size()}）
                span(style='float:right;')
                    if roleData
                        button.layui-btn.layui-btn-small.green(href="/admin/role/seluser.html?role=" + roleData.id, data-toggle="ajax", data-width="750", data-title="添加用户到角色")
                            | 添加用户到角色
                        if user.superadmin
                            button.layui-btn.layui-btn-original.layui-btn-small(href="/admin/role/edit.html?id=" + roleData.id, data-toggle="ajax", data-width="550", data-height="200", data-title="修改角色")
                                | 修改角色
                        button.layui-btn.layui-btn-warm.layui-btn-small(href="/admin/role/auth.html?id=" + roleData.id, data-toggle="ajax", title="角色授权", data-width="400", data-height="500")
                            | 角色授权
                        if user.superadmin
                            button.layui-btn.layui-btn-danger.layui-btn-small(href="/admin/role/delete.html?id=" + roleData.id, data-toggle="tip", data-title="请确认是否删除角色？")
                                | 删除角色
            .row(style='padding:5px;')
                .col-lg-12
                    table.layui-table(lay-skin='line')
                        colgroup
                            col(width='20%')
                            col(width='30%')
                            col(width='20%')
                            col(width='25%')
                            col(width='24%')
                            col(width='1%')
                            col
                        thead
                            tr
                                th 组织
                                th 用户
                                th 姓名
                                th 电子邮件
                                th 手机
                                th(style='white-space:nowrap;', nowrap) 操作
                        tbody(style='table-layout: fixed; word-break: break-all;')
                            if userRoleList && userRoleList.content
                                for userRole in userRoleList.content
                                    tr
                                        td= userRole.user.currOrganName
                                        td(style="width:150px")
                                            a(href="")
                                                i.layui-icon.headimg 
                                                div(style="margin-left:50px;margin-top:0px;")
                                                    | #{userRole.user.username}
                                                    div(style="color:#aaaaaa;font-size:12px;")
                                                        | #{userRole.role.name}
                                        td(style="width:150px")= userRole.user.uname
                                        td(style="wdth:150px")= userRole.user.email
                                        td= userRole.user.mobile
                                        td(style="white-space: nowrap;")
                                            a(href="/admin/role/user/delete.html?id=" + userRole.id + "&role=" + userRole.role.id, data-toggle="tip", data-title="请确认是否移除？")
                                                i.layui-icon(style="color:red;") ဆ
                                                | 移除
                            else
                                td(colspan="5", style="height: 400px;")
                                    .ukefu-empty(style="background: none;")
                                        i.layui-icon 
                                        div(style="") 还没有系统用户

            .row(style='padding:5px;')
                .col-lg-12#page(style='text-align:center;')
    script.
        layui.use('layer', function () {
            var layer = layui.layer
            var msg = '#{msg}';
            if (msg == 'admin_role_save_success')
                layer.msg('添加成功', {icon: 1, time: 1000})
            else if (msg == 'admin_role_save_exist') {
                layer.msg('角色添加失败，角色已存在', {icon: 2, time: 3000})
            } else if (msg == 'admin_role_update_success') {
                layer.msg('角色修改成功', {icon: 1, time: 1000})
            } else if (msg == 'admin_role_update_not_exist') {
                layer.msg('角色修改失败', {icon: 2, time: 3000})
            }
        });

